package jym.tan.movielibrary.utils;

import java.awt.Component;
import java.awt.Container;

import javax.swing.JOptionPane;

import jym.tan.movielibrary.constant.ComponentConstant;

public class ComponentUtils {

	public static void enableChildComponents(Container container) {
		toggleEnableDisableChildComponents(container, true);
	}
	
	public static void disableChildComponents(Container container) {
		toggleEnableDisableChildComponents(container, false);
	}
	
	private static void toggleEnableDisableChildComponents(Container container, Boolean enable) {
		for (Component childComponent : container.getComponents()) {
			if (childComponent instanceof Container) {
				toggleEnableDisableChildComponents((Container) childComponent, enable);
			} 
			
			childComponent.setEnabled(enable);
		}
	}
	
	public static void showErrorMessage(Component parent, String message) {
		JOptionPane.showMessageDialog(parent, message, ComponentConstant.Title.ERROR_MESSAGE_DIALOG, JOptionPane.ERROR_MESSAGE);
	}
	
	public static void showWarningMessage(Component parent, String message) {
		JOptionPane.showMessageDialog(parent, message, ComponentConstant.Title.WARNING_MESSAGE_DIALOG, JOptionPane.WARNING_MESSAGE);
	}
}
